<template>
    <div class="page">
        <div class="line">
            <div class="score-box">
                <div class="title-cell">我的积分</div>

                <div class="score-num">
                    {{ userStore.midNum.score_num }}
                    <span class="score-unit">积分</span>
                </div>

                <div class="btn-group">
                    <div class="btn-item-1" @click="onTaskList">获取积分</div>
                    <div class="btn-item-2" @click="onScoreLottery">
                        积分抽奖
                    </div>
                </div>
            </div>

            <div class="bill-box">
                <div class="title-cell">积分账单</div>

                <div class="bill-list">
                    <div class="bill-item" v-for="item in userStore.scoreLog" :key="item.id">
                        <div class="bill-item__time">{{ item.createtime }}</div>
                        <div class="bill-item__text">{{ item.desc }}</div>
                        <div class="bill-item__score">
                            {{ item.score >= 0 ? "+" : ""
                            }}{{
    Math.abs(item.score) >= 10000
    ? item.score / 10000 + "万"
    : item.score
}}积分
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="exchange-box">
            <div class="title-cell">积分兑换</div>

            <div class="exchange-list">
                <div class="exchange-item" v-for="(item, index) in exchangeList" :key="item.code">
                    <div class="exchange-item-box" :class="'exchange-item-' + (index + 1)">
                        <div class="exchange-score-num">
                            {{
                                item.score >= 10000
                                ? item.score / 10000 + "万"
                                : item.score
                            }}积分
                        </div>
                        <div class="exchange-name">
                            <template v-if="item.type === 'vip'">
                                <p>基础版（Web端）</p>
                                <p>{{ item.value }}天会员</p>
                            </template>
                            <template v-else-if="item.type === 'money'">
                                <p>积分抵扣</p>
                                <p>{{ item.value }}元</p>
                            </template>
                            <template v-else-if="item.type === 'discount'">
                                <p>会员{{ item.value }}折</p>
                                <p>折扣卷</p>
                            </template>
                        </div>
                    </div>
                    <div class="exchange-btn" @click="onExchange(item)">
                        立即兑换
                    </div>
                </div>
            </div>
        </div>
    </div>

    <DialogTemplateChooseP ref="dialogTemplateChooseRef" @confirm="onConfirm" />
</template>
<script setup>
import { useContent } from ".";

const {
    dialogTemplateChooseRef,
    exchangeList,

    getScoreExchange,
    onTaskList,
    onScoreLottery,
    onExchange,
    onConfirm
} = useContent();

const userStore = useUserStore();
GET_SCORE_LOG();

await getScoreExchange();
</script>
<style lang="scss" scoped>
.page {
    width: 100%;
    padding: 16px;
}

.line {
    display: flex;
    justify-content: space-between;
}

.score-box {
    width: 450px;
    height: 250px;
    background: #fff;
    border-radius: 6px;
    padding: 15px;

    .score-num {
        display: flex;
        align-items: flex-end;
        justify-content: center;
        font-weight: bold;
        font-size: 40px;
        line-height: 35px;
        color: #5085fb;
        margin-top: 50px;

        .score-unit {
            display: inline-block;
            font-size: 18px;
            height: 18px;
            line-height: 18px;
            color: #111;
        }
    }

    .btn-group {
        display: flex;
        justify-content: space-around;
        margin-top: 50px;
        padding: 0 8px;

        .btn-item-1,
        .btn-item-2 {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 130px;
            height: 44px;
            border-radius: 4px;
            font-size: 18px;
            color: #fff;
            cursor: pointer;
            user-select: none;
        }

        .btn-item-1 {
            background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/icon-btn-1.jpg");
        }

        .btn-item-2 {
            background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/icon-btn-2.jpg");
        }
    }
}

.bill-box {
    width: 664px;
    height: 250px;
    background: #fff;
    border-radius: 6px;
    padding: 15px;

    .bill-list {
        margin-top: 29px;
        overflow: auto;
        height: 170px;

        .bill-item {
            display: flex;
            margin-bottom: 23px;

            &:last-of-type {
                margin-right: 0;
            }

            &__time {
                font-size: 16px;
                color: #333;
            }

            &__text {
                width: 250px;
                font-size: 16px;
                color: #333;
                margin-left: 20px;
                text-align: center;
            }

            &__score {
                color: #5185fb;
                font-size: 16px;
                margin-left: 60px;
            }
        }
    }
}

.exchange-box {
    width: 100%;
    height: 620px;
    background-color: #fff;
    margin-top: 16px;
    padding: 15px;

    .exchange-list {
        display: flex;
        flex-wrap: wrap;
        margin-top: 20px;

        .exchange-item {
            margin-right: 16px;
            margin-bottom: 30px;

            &:nth-of-type(4n) {
                margin-right: 0;
            }
        }

        .exchange-btn {
            width: 110px;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 4px;
            border: 1px solid #5085fb;
            color: #5085fb;
            margin: 16px auto 0;
            cursor: pointer;
        }

        .exchange-item-box {
            position: relative;
            width: 260px;
            height: 200px;
            flex-shrink: 0;
            background-size: 100% 100%;
            border-radius: 4px;
            color: #333;
            font-size: 20px;

            .exchange-score-num {
                display: flex;
                align-items: center;
                justify-content: center;
                width: 150px;
                height: 40px;
                position: absolute;
                top: 0;
                left: 0;
                background-size: 100% 100%;
                color: #fff;
                font-size: 24px;
            }

            .exchange-name {
                padding-top: 85px;
                text-align: center;
                line-height: 28px;
                font-size: 20px;
                color: #333;
                font-weight: bold;
            }
        }

        .exchange-item-1 {
            background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/bg-day1.jpg");

            .exchange-score-num {
                background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/icon-lefttop-3.png");
            }
        }

        .exchange-item-2 {
            background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/bg-day3.jpg");

            .exchange-score-num {
                background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/icon-lefttop-3.png");
            }
        }

        .exchange-item-3 {
            background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/bg-day7.jpg");

            .exchange-score-num {
                background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/icon-lefttop-3.png");
            }
        }

        .exchange-item-4 {
            background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/bg-score.jpg");

            .exchange-score-num {
                background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/icon-lefttop-1.png");
            }
        }

        .exchange-item-5 {
            background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/bg-discount.jpg");

            .exchange-score-num {
                background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/icon-lefttop-2.png");
            }
        }
    }
}

.title-cell {
    position: relative;
    line-height: 20px;
    padding-left: 14px;

    &::before {
        position: absolute;
        left: 0;
        top: 0;
        content: "";

        width: 4px;
        height: 20px;
        background: #5085fb;
        border-radius: 2px;
    }
}
</style>
